package br.com.aquinoevasconcelos.servlets.administrador;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.aquinoevasconcelos.fachada.Fachada;
import br.com.aquinoevasconcelos.modelos.Endereco;
import br.com.aquinoevasconcelos.user.UsuarioAdm;

/**
 * Servlet implementation class RemoverAdministrador
 */
@WebServlet("/RemoverAdministrador")
public class RemoverAdministrador extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public RemoverAdministrador() {
		super();
	}

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		Fachada fachada = Fachada.getInstancia();
		UsuarioAdm adm = new UsuarioAdm();

		adm.setId(Integer.parseInt(request.getParameter("id")));
		String senhaMestre = request.getParameter("senhaMestre");
		try {
			if (fachada.validarSenhaMestre(senhaMestre) == true){
				fachada.removerADM(adm);
				
				response.sendRedirect("EncaminharPainelAdm?msg=erro");	
			}
			else{
				
				response.sendRedirect("EncaminharPainelAdm?msg=sucesso");
			}

			

		
		} catch (Exception e) {
			RequestDispatcher rd = request.getRequestDispatcher("../erro.jsp");
			rd.forward(request, response);
			e.printStackTrace();

		}

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

}
